﻿#include<iostream>
#include<map>
using namespace std;
class person
{
public:
	person(std::string name)
	{
		this->m_Name = name;
		//this->m_Age = age;
	}
	std::string m_Name;
	//int m_Age;
};

void printMap(std::map<int,person> &m)
{
	for (std::map<int , person>::iterator it = m.begin(); it != m.end(); ++it)
	{
		std::cout << "年龄：" << it->first << "  姓名：" << it->second.m_Name << '\n';
	}
	std::cout << '\n';
}

void test01()
{
	std::map<int,person> m1;
	/*person p1( 18,"张三");
	person p2( 20,"李四");
	person p3( 19,"王五");
	person p4( 72,"老六");*/

	m1.insert(std::make_pair(18, "张三"));
	m1.insert(std::make_pair(20, "李四"));
	m1.insert(std::make_pair(19, "王五"));
	m1.insert(std::make_pair(72, "老六"));

	printMap(m1);

	std::cout << "请输入年龄：" << '\n';
	int a = 0;
	std::cin >> a;
	std::map<int, person>::iterator pos = m1.find(a);
	if (pos != m1.end())
	{
		std::cout << "找到该人：" << pos->second.m_Name << '\n';
	}
	else
	{
		std::cout << "未找到该人" << '\n';
	}


	int num = m1.count(72);
	std::cout << "num = " << num << '\n';
}

int main()
{
	test01();

	return 0;
}
